import util from '@/libs/util';
import utilDate from '@/util/getDate';
import Cookies from 'js-cookie';
import customTree from '../studentsignup/customTree.vue';
import attendanceInfo from './attendanceInfo.vue';

export default {
    name: 'exportable-table',
    components: {
        customTree, attendanceInfo
    },
    data () {
        return {
            columns: [{
                title: '班级名称',
                key: 'name'
            }, {
                title: '部门',
                key: 'departmentName'
            }, {
                title: '专业',
                key: 'marjorName'
            }, {
                title: '开课时间',
                key: 'classStarttime',
                render: (h, params) => {
                    return h('div', {}, utilDate.getDate(params.row.classStarttime, 'time'));
                },
                width: 105
            }, {
                title: '结课时间',
                key: 'classEndtime',
                render: (h, params) => {
                    return h('div', {}, utilDate.getDate(params.row.classEndtime, 'time'));
                },
                width: 105
            }, {
                title: '负责老师',
                key: 'mainTeacherName'
            }, {
                title: '录取方式',
                key: 'classApply'
            }, {
                title: '发布状态',
                key: 'releaseStatus',
                render: function (h, params) {
                    let text = '已发布';
                    return h('div', {}, text);
                }
            }, {
                title: '点到次数',
                key: ''
            }, {
                title: '最近点到时间',
                key: ''
            }, {
                title: '操作',
                key: 'action',
                width: 100,
                align: 'center',
                render: (h, params) => {
                    return h('div', [
                        h('Button', {
                            props: {
                                type: 'primary',
                                size: 'small'
                            },
                            style: {
                                marginRight: '5px'
                            },
                            on: {
                                click: () => {
                                    this.modelVisible = true;
                                    this.entity.id = params.row.id;
                                }
                            }
                        }, '点到列表')
                    ]);
                }
            }],
            dataList: [],
            entity: {},
            modelVisible: false,
            formData: {}, // 新增/编辑表单数据
            pageSize: 5, // 分页数据
            pageIndex: 1, // 分页数据
            total: 0,
            classSeasonList: [],
            deptModal: false,
            baseuser: JSON.parse(Cookies.get('baseUser')),
            query: {}
        };
    },
    mounted () {
        this.init();
    },
    methods: {
        init: function () { // 页面初始化
            util.ajax.post('/base/datadictionary/findByCode', util.toFormData(
                {CODE: 'CLASS_SEASON'}
            )).then(res => { // 学期数据
                if (res.data.code == 200) {
                    var data = res.data.data;
                    this.classSeasonList = data;
                }
            });
            util.ajax.post('/base/datadictionary/findByCode', util.toFormData(
                {CODE: 'MAJOR_LEVEL'}
            )).then(res => { // 获得区域数据
                if (res.data.code == 200) {
                    var data = res.data.data;
                    this.majorLevelList = data;
                }
            });
            this.doQuery();
        },
        doQuery: function () {
            util.ajax.post('/base/class/list', util.toFormData({
                page: this.pageIndex,
                size: this.pageSize,
                name: this.query.name ? this.query.name : '',
                classSeason: this.query.classSeason ? this.query.classSeason : '',
                departmentId: this.query.departmentId ? this.query.departmentId : '',
                releaseStatus: '2',
                organizeId: this.baseuser.orgId
            })).then(res => {
                if (res.data.data) {
                    // debugger;
                    this.dataList = res.data.data.list;
                    this.total = res.data.data.total;
                    console.log(this.entity)
                }
            });
        },
        setDept () {
            if (this.$refs.dept.selectData[0]) {
                this.query.departmentId = this.$refs.dept.selectData[0].id;
                this.query.departmentName = this.$refs.dept.selectData[0].title;
            } else {
                this.query.departmentId = '';
                this.query.departmentName = '';
            }
            this.deptModal = false;
        },
        cancelSelect () {
            this.$refs.dept.cancelSelect();
        }
    }
};
